package com.woniuxy.common.exception;

import com.woniuxy.common.Result;
import com.woniuxy.common.enums.IResultCode;
import com.woniuxy.common.enums.impl.ResultCode;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalException {
    /**
     *@ExceptionHandler注解指定要处理的类型
     */
    @ExceptionHandler(BusinessException.class)
    public Result handleBusinessException(BusinessException e){
        e.printStackTrace();//打印错误信息
        IResultCode resultCode = e.getResultCode();
        return Result.fail(resultCode);
    }
    /**
     * 没有精确匹配异常，按Exception处理
     */
    @ExceptionHandler(Exception.class)
    public Result handleException(Exception e){
        e.printStackTrace();
        return  Result.fail(ResultCode.FAIL);
    }
}
